package com.zhudoo.zhilian.util;

import com.alibaba.fastjson.JSONObject;
import com.zhudoo.zhilian.dao.entity.User;

import java.util.Date;

/**
 * @author zhudao
 */
public class TokenUtil {

    /**
     * 创建token
     *
     * @param user
     */
    public static void createToken(User user) {
        Date tokenExpiredTime = DateUtil.addMonth(new Date(), 1);
        JSONObject jsonToken = new JSONObject();
        jsonToken.put("id", user.getId());
        jsonToken.put("openId", user.getOpenId());
        jsonToken.put("tokenExpiredTime", tokenExpiredTime);
        String token = MD5Util.md5Encode(jsonToken.toJSONString());
        user.setToken(token);
        user.setTokenExpiredTime(tokenExpiredTime);
    }
}
